Python for Finance Cookbook - Second Edition by Eryk Lewinson

Python for Finance Cookbook - Second Edition by Eryk Lewinson

Author:Eryk Lewinson
Language: eng
Format: epub
Publisher: Packt
Published: 2022-01-15T00:00:00+00:00


Plot the efficient frontier: MARKERS = ["o", "X", "d", "*"] fig, ax = plt.subplots() portf_results_df.plot(kind="scatter", x="volatility", y="returns", c="sharpe_ratio", cmap="RdYlGn", edgecolors="black", ax=ax) ax.set(xlabel="Volatility", ylabel="Expected Returns", title="Efficient Frontier") ax.plot(ef_vol_list, ef_rtn_list, "b--") for asset_index in range(n_assets): ax.scatter(x=np.sqrt(cov_mat.iloc[asset_index, asset_index]), y=avg_returns[asset_index], marker=MARKERS[asset_index], s=150, color="black", label=ASSETS[asset_index]) ax.legend() plt.show()

Executing the snippet generates the plot with all the randomly created portfolios, four points indicating the individual assets, and the efficient frontier.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.